package org.meichao.demo.service.sequence;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 通过countDownLatch控制线程执行顺序
 */
public class CountDownLatchMain {

    public static void main(String[] args) {
        CountDownLatch countDownLatchAB = new CountDownLatch(1);
        CountDownLatch countDownLatchBC = new CountDownLatch(1);

        CountDownLatchA a = new CountDownLatchA(countDownLatchAB);
        CountDownLatchB b = new CountDownLatchB(countDownLatchAB,countDownLatchBC);
        CountDownLatchC c = new CountDownLatchC(countDownLatchBC);

        ExecutorService executorService = Executors.newFixedThreadPool(10);
        executorService.execute(a);
        executorService.execute(b);
        executorService.execute(c);

        executorService.shutdown();
    }
}
